package com.springmvc.web.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.springmvc.web.dao.IUserDao;
import com.springmvc.web.entity.User;
import com.springmvc.web.mapper.UserMapper;



@Repository
public class UserDaoImpl extends SqlSessionTemplate implements IUserDao {    
	
	
	 private UserMapper userMapper;
	
	 @Autowired	 
	 public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
		    super(sqlSessionFactory);
		    userMapper = super.getMapper(UserMapper.class);
	  }
	 
	
	   //添加
	   @Override
	   public void addUser(User user) {
				 		 	
		   userMapper.addUser(user);
	   }
	   
	   
	    //删除	
		@Override
		public void delUser(Integer id) {
			
			userMapper.delUser(id);			
		}

	
	    //根据id查找
		@Override
		public User getUser(Integer id) {
						
			return userMapper.getUser(id);
		}

		
	    //根据用户名查找
		@Override
		public List<User> getUserByName(int rows,int startrow,String username) {
			
			Map<String,Object> params = new HashMap<String, Object>();
			    
			    params.put("rows", rows);
				params.put("startrow", startrow);
				params.put("username", username);
			
			    return userMapper.getUserByName(params);
		}
		
		
	    //修改
		@Override
		public void updateUser(User user) {
						
			userMapper.updateUser(user);
		}


	    //查询所有
	   /* @Override
		public Map<String, User> getMap() {
			
	    	return userMapper.getMap();
		}*/
		@Override
		public List<User> getAllUser() {

			return userMapper.getAllUser();
		}


		@Override
		public int getTotal() {
			
			return userMapper.getTotal();
		}


		@Override
		public List<User> selectUserByPager(int rows,int startrow,Integer id, String username) {
			
			Map<String,Object> params = new HashMap<String, Object>();
				
			    params.put("rows", rows);
				params.put("startrow", startrow);
				params.put("id", id);
				params.put("username", username);
				
				
				return userMapper.selectUserByPager(params);
		}

}



